<?php 
$get_field_set_string = ''; 
if(isset($fieldset)){
    foreach($fieldset as $key=>$value):
    	switch(strtolower($value['type'])){
    		case 'htmltext':
    		case 'textdata':
    			$field_content = $$key;
    			break;
    		case 'multitext':
    			$field_content = '<textarea name="'.$key.'" id="'.$key.'" class="multi-line">'.$$key.'</textarea>';
    			break;
    		case 'datetime':
    			$field_content = '<input type="text" name="'.$key.'" id="'.$key.'" value="'.date('Y-m-d H:m:s',strtotime($$key)).'" class="sing-line input-name" onClick="WdatePicker();" readonly="readonly" />';
    			break;
    		case 'imgfile':
    		case 'text':
    		case 'textchar':
    		case 'int':
    		case 'float':
    			$field_content = '<input type="text" name="'.$key.'" id="'.$key.'" value="'.$$key.'" class="sing-line input-name" />';
    			break;
    		case 'select':
    			$field_content = '<select name="'.$key.'" id="'.$key.'" size="1">';
    			$option = explode(',',$value['default']);
    			foreach($option as $option_item){
    				if(!strstr($option_item,'=')){
	    				$field_content .= '<option value="'.$option_item .'"';
	    				if($$key==$option_item) $field_content .= ' selected="selected"';
	    				$field_content .= '>'.$option_item.'</option>';
    				}else{
    					list($txt,$val) = explode('=',$option_item);
    					$field_content .= '<option value="'.$val.'"';
    					if($$key==$val) $field_content .= ' selected="selected"';
    					$field_content .= '>'.$txt.'</option>';
    				}
    			}
    			$field_content .= '</select>';
    			break;
    		case 'radio':
    			$field_content = '';
    			$radio = explode(',',$value['default']);
    			foreach($radio as $radio_item){
    				if(!strstr($radio_item,'=')){
    					$field_content .= '<input type="radio" name="'.$key.'" id="'.$key.'_'.$radio_item.'" value="'.$radio_item.'"';
    					if($$key==$radio_item) $field_content .= ' checked="checked"';
    					$field_content .= ' /><label for="'.$key.'_'.$radio_item.'">'.$radio_item.'</label>';
    				}else{
    					list($txt,$val) = explode('=',$radio_item);
    					$field_content .= '<input type="radio" name="'.$key.'" id="'.$key.'_'.$val.'" value="'.$val.'"';
    					if($$key==$val) $field_content .= ' checked="checked"';
    					$field_content .= ' /><label for="'.$key.'_'.$val.'">'.$txt.'</label>';
    				}
    			}
    			break;
    		case 'checkbox':
    			$field_content = '';
    			$radio = explode(',',$value['default']);
    			foreach($radio as $radio_item){
    				if(!strstr($radio_item,'=')){
    					$field_content .= '<input type="checkbox" name="'.$key.'[]" id="'.$key.'_'.$radio_item.'" value="'.$radio_item.'"';
    					if($$key==$radio_item) $field_content .= ' checked="checked"';
    					$field_content .= ' /><label for="'.$key.'_'.$radio_item.'">'.$radio_item.'</label>';
    				}else{
    					list($txt,$val) = explode('=',$radio_item);
    					$field_content .= '<input type="checkbox" name="'.$key.'[]" id="'.$key.'_'.$val.'" value="'.$val.'"';
    					if($$key==$val) $field_content .= ' checked="checked"';
    					$field_content .= ' /><label for="'.$key.'_'.$val.'">'.$txt.'</label>';
    				}
    			}
    			break;
    		case 'img':
    		case 'media':
    		case 'addon':
    			/*$upfileext = '';
    			switch(strtolower($value['type'])){
    				case 'img':
    					$upfileext = 'gif,jpg,jpeg,bmp,png';
    					break;
    				case 'media':
    					$upfileext = 'flv,swf,wmv,avi,3g,mp4,rmvb';
    					break;
    				case 'addon':
    					$upfileext = 'doc,docx,rar,zip,ppt,txt';
    					break;
    			}*/
    			$field_content = '<table cellspdding="0" cellspacing="0" width="100%">
      		<tr>
      			<td style="width:94%;"><input type="text" name="'.$key.'" id="'.$key.'" class="sing-line input-title" value="'.$$key.'" /></td>
      			<td style="width:40px; text-align:center;"><a href="#'.strtolower($value['type']).'" class="upload">上传</a></td>
      		</tr>
      	</table>';
    			break;
    	}
    	$get_field_set_string .= '<tr>
      <td class="guid">'.$value['itemname'].'：</td>
      <td class="formItem">'.$field_content.'</td>
    </tr>';
    endforeach;
}
$this->load->view("admin/$adminCurrentTemplate/commonHead2");?>
<table width="99%" border="0" cellspacing="1" cellpadding="0" class="editFormContainer">
    <form id="editForm" name="editForm" method="post" action="<?=$this->input->server('REQUEST_URI')?>">
	<input type="hidden" name="id" id="id" value="<?=$id?>" />
    <tr>
      <td class="guid">启用状态：</td>
      <td class="formItem">	  	
		<table cellspdding='0' cellspacing='0' width='100%'>
			<tr>
				<td style="width:40%;">
					<input type="radio" name="disabled" id="disabled-0" value="0" checked/><label for="disabled-0"<?php if(isset($disabled)) if($disabled==0 && strlen($disabled)>0) echo ' checked'?>>启用</label>
					<input type="radio" name="disabled" id="disabled-1" value="1"<?php if(isset($disabled)) if($disabled==1 && strlen($disabled)>0) echo ' checked'?> /><label for="disabled-1">禁用</label>
				</td>
				<td class="guid">审核状态：</td>
				<td class="formItem">
			  	<input type="radio" name="ismake" id="ismake-0" value="0" checked/><label for="ismake-0"<?php if($ismake==0) echo ' checked'?>>未审核</label>
				<input type="radio" name="ismake" id="ismake-1" value="1"<?php if($ismake==1) echo ' checked'?> /><label for="ismake-1">已审核</label>
				</td>
			</tr>
		</table>
	  </td>
    </tr>
    <tr>
      <td class="guid">文档属性：</td>
      <td class="formItem">
	  		<input type="checkbox" name="flag[]" id="flag_h" value="h"<?php if(isset($flag)) if(strstr($flag,'h')) echo ' checked'?> /><label for="flag_h">头条[h]</label>
			<input type="checkbox" name="flag[]" id="flag_c" value="c"<?php if(isset($flag)) if(strstr($flag,'c')) echo ' checked'?> /><label for="flag_c">推荐[c]</label>
			<input type="checkbox" name="flag[]" id="flag_p" value="p"<?php if(isset($flag)) if(strstr($flag,'p')) echo ' checked'?> /><label for="flag_p">图片[p]</label>
			<input type="checkbox" name="flag[]" id="flag_j" value="j"<?php if(isset($flag)) if(strstr($flag,'j')) echo ' checked'?> /><label for="flag_j">跳转[j]</label>
			<input type="checkbox" name="flag[]" id="flag_f" value="f"<?php if(isset($flag)) if(strstr($flag,'f')) echo ' checked'?> /><label for="flag_f">幻灯[f]</label>
			<input type="checkbox" name="flag[]" id="flag_s" value="s"<?php if(isset($flag)) if(strstr($flag,'s')) echo ' checked'?> /><label for="flag_s">滚动[s]</label>
      </td>
    </tr>
    <tr class="redirecturl<?php 
    if(!isset($flag)){
    	echo ' hide';
    }else if(!strstr($flag,'j')){
    	echo ' hide';
    }?>">
      <td class="guid">跳转网址：</td>
      <td class="formItem"><input type="text" name="redirecturl" id="redirecturl" class="sing-line input-title" value="<?php if(isset($redirecturl)) echo $redirecturl?>" /></td>
    </tr>
    <tr>
      <td class="guid">来　　源：</td>
      <td class="formItem">	  	
		<table cellspdding='0' cellspacing='0' width='100%'>
			<tr>
				<td style="width:40%;">
					<input type="text" name="source" id="source" class="sing-line input-title" style="margin:0; padding:0;" value="<?php if(isset($source)) echo $source?>" />
				</td>
				<td class="guid">作　　者：</td>
				<td class="formItem"><input type="text" name="author" id="author" class="sing-line input-title" value="<?php if(isset($author)) echo $author?>" /></td>
			</tr>
		</table>
	  </td>
    </tr>
    <tr>
      <td class="guid">点击次数：</td>
      <td class="formItem">
		<table cellspdding='0' cellspacing='0' width='100%'>
			<tr>
				<td style="width:40%;">
					<input type="text" name="click" id="click" class="sing-line input-title" style="margin:0; padding:0;" value="<?php if(isset($click)) echo $click?>" />
				</td>
				<td class="guid">颜　　色：</td>
				<td class="formItem"><input type="text" name="color" id="color" class="sing-line input-title" value="<?php if(isset($color)) echo $color?>" /></td>
			</tr>
		</table>
	  </td>
    </tr>
    <tr>
      <td class="guid">好 评 数：</td>
      <td class="formItem">
		<table cellspdding='0' cellspacing='0' width='100%'>
			<tr>
				<td style="width:40%;">
					<input type="text" name="goodpost" id="goodpost" class="sing-line input-title" style="margin:0; padding:0;" value="<?php if(isset($goodpost)) echo $goodpost?>" />
				</td>
				<td class="guid">坏 评 数：</td>
				<td class="formItem"><input type="text" name="badpost" id="badpost" class="sing-line input-title" value="<?php if(isset($badpost)) echo $badpost?>" /></td>
			</tr>
		</table>
	  </td>
    </tr>
    <tr>
      <td class="guid">文 件 名：</td>
      <td class="formItem">
		<table cellspdding='0' cellspacing='0' width='100%'>
			<tr>
				<td style="width:40%;">
					<input type="text" name="filename" id="filename" maxsize="40" class="sing-line input-title" style="margin:0; padding:0;" value="<?php if(isset($filename)) echo $filename?>" />
				</td>
				<td class="guid">模板文件：</td>
				<td class="formItem"><input type="text" name="template" id="template" maxsize="30" class="sing-line input-title" value="<?php if(isset($template)) echo $template?>" /></td>
			</tr>
		</table>
	  </td>
    </tr>
    <tr>
      <td class="guid">更新时间：</td>
      <td class="formItem">
		<table cellspdding='0' cellspacing='0' width='100%'>
			<tr>
				<td style="width:40%;">
					<input type="text" name="updateTime" id="updateTime" class="sing-line input-title" style="margin:0; padding:0;" value="<?php if(isset($updateTime)) echo $updateTime?>" onClick="WdatePicker();"  readonly="readonly" />
				</td>
				<td class="guid">发布时间：</td>
				<td class="formItem"><input type="text" name="createTime" id="createTime" class="sing-line input-title" value="<?php if(isset($createTime)) echo $createTime?>" onClick="WdatePicker();"  readonly="readonly" /></td>
			</tr>
		</table>
	  </td>
    </tr>
    <tr>
      <td class="guid">所属栏目：</td>
      <td class="formItem">	  	
		<table cellspdding='0' cellspacing='0' width='100%'>
			<tr>
				<td style="width:40%;"><select name="categoryId" id="categoryId" size="1" class="sing-select"><?php 
      	$str = '';
		foreach ($categoryList as $value){
			$str .= "<option value=\"".$value->id."\"";
			if(isset($categoryId)){
				if($value->id==$categoryId){
					$str .= " selected=\"selected\"";
				}
			}
			$str .=">";
			for($i=1;$i<$value->deep;$i++){
				$str .= "&nbsp;|-";
			}
			$str .= $value->title."</option>\n";
		}
		echo $str;
      	?></select></td>
				<td class="guid">排序索引：</td>
				<td class="formItem"><input type="text" name="oIndex" id="oIndex" class="sing-line input-title" value="<?php if(isset($oIndex)) echo $oIndex?>" /></td>
			</tr>
		</table>
	  </td>
    </tr>
    <tr>
      <td class="guid">文档标题：</td>
      <td class="formItem"><input type="text" name="title" id="title" class="sing-line input-title" value="<?php if(isset($title)) echo $title?>" /></td>
    </tr>
    <tr>
      <td class="guid">缩 略 图：</td>
      <td>
      	<table cellspdding="0" cellspacing="0" width="100%">
      		<tr>
      			<td style="width:94%;"><input type="text" name="litpic" id="litpic" class="sing-line input-title" value="<?php if(isset($litpic)) echo $litpic?>" /></td>
      			<td style="width:40px; text-align:center;"><a href="#img" class="upload-litpic">上传</a></td>
      		</tr>
      	</table>
      </td>
    </tr>
    <tr>
      <td class="guid">短 标 题：</td>
      <td class="formItem"><input type="text" name="shortTitle" id="shortTitle" class="sing-line input-name" value="<?php if(isset($shortTitle)) echo $shortTitle?>" /></td>
    </tr>
    <tr>
      <td class="guid">关 键 词：</td>
      <td class="formItem"><input type="text" name="keywords" id="keywords" maxsize="30" class="sing-line input-name" value="<?php if(isset($keywords)) echo $keywords?>" /></td>
    </tr>
    <tr>
      <td class="guid">描　　述：</td>
      <td class="formItem"><textarea name="description" id="description" maxsize="255" class="multi-line"><?php if(isset($description)) echo $description?></textarea></td>
    </tr><?php
		echo $get_field_set_string;
    ?>
</form>
</table>
<?php $this->load->view("admin/$adminCurrentTemplate/commonFoot2");?>

<script type="text/javascript">
var tvName = '<?php if(isset($tvName)) echo $tvName;?>';
$(function(){
	$('#title').bind('blur',titleBlur);
	var id = $('#id').val();
	dg.addBtn('subBtn','提 交',subForm);
	if(id.length==0) dg.SetTitle('添加文档');
	$('input[name^="flag"]').bind('click',flagClick);
	$.getColor($('#color'),$('input[name="title"]'),$('#color'));
	$('.upload-litpic').bind('click',uploadLitpic);
	$('.upload').bind('click',upload);
	$('#categoryId').bind('change',categoryIdChange).change();
})

var flagClick = function(){
	if(this.value=='j' && this.checked){
		$('.redirecturl').show();
	}else{
		$('.redirecturl').hide();
	}
}

var titleBlur = function(){
	var id = $.trim($('#id').val());
	var title = $.trim($('#title').val());
	var categoryId = $.trim($('#categoryId').val());
	$.ajax({
		type:'POST',
		url:getInfo + '/check/',
		data:'tvName=' + tvName + '&parentIdOrCategoryIdFieldName=categoryId&parentIdOrCategoryIdFieldValue=' + categoryId + '&fieldName=title&fieldValue=' + title + '&id=' + id,
		success:function(returnValue){
			if(parseInt(returnValue)>0){
				subMess(228,108,'文档标题错误','<span class="red">对不起，此标题文档已经存在！</span>',$("#title"));
				return false;
			}
		}
	});
}

var uploadLitpic = function(){
	var uploadType = $(this).attr('href').replace('#','').toLowerCase();
	var returnInput = $(this).parent().siblings().eq(0).children().eq(0).attr('id');
	var uploadUrl = '<?php echo site_url('admin/upload')?>?type=' + uploadType + '&returnInput=' + returnInput;
	if($.browser.msie){
		var lockedScroll = true;
	}else if($.browser.mozilla){
		var lockedScroll = false;
	}else if($.browser.safari){
		var lockedScroll = false;
	}else{
		var lockedScroll = false;
	}
	var uploadLitpicDialog = new dg.curWin.$.dialog({
			id:'uploadLitpicDialog',
			parent:dg,
			width:331,
			height:106,
			title:'上传缩略图',
			cover:true,
			iconTitle:false,
			rang:true,
			maxBtn:false,
			lockScroll:lockedScroll,
			autoPos:true,
			cancelBtn:false,
			resize:false,
			page:uploadUrl
		});
	uploadLitpicDialog.ShowDialog();
	return false;
}

var upload = function(){
	var uploadType = $(this).attr('href').replace('#','').toLowerCase();
	var returnInput = $(this).parent().siblings().eq(0).children().eq(0).attr('id');
	var uploadUrl = '<?php echo site_url('admin/upload')?>?type=' + uploadType + '&returnInput=' + returnInput;
	if($.browser.msie){
		var lockedScroll = true;
	}else if($.browser.mozilla){
		var lockedScroll = false;
	}else if($.browser.safari){
		var lockedScroll = false;
	}else{
		var lockedScroll = false;
	}
	switch(uploadType){
		case 'img':
			var uploadDialogTitle = '上传图片';
			break;
		case 'media':
			var uploadDialogTitle = '上传媒体文件';
			break;
		default:
			uploadDialogTitle = '上传文件';
			break;
	}
	uploadDialogTitle = '上传' + $(this).parents('table').parent().siblings().eq(0).html().replace('：','');
	var uploadDialog = new dg.curWin.$.dialog({
			id:'uploadDialog',
			parent:dg,
			width:331,
			height:106,
			title:uploadDialogTitle,
			cover:true,
			iconTitle:false,
			rang:true,
			maxBtn:false,
			lockScroll:lockedScroll,
			autoPos:true,
			cancelBtn:false,
			resize:false,
			page:uploadUrl
		});
	uploadDialog.ShowDialog();
	return false;
}

var categoryIdChange = function(){
	var id = $.trim($('#id').val());
	var thisValue = $(this).val();
	var oIndex = $.ajax({async:false,url:getInfo + '/archivesCategoryChange/?tvName=' + tvName + '&categoryId=' + thisValue + '&id=' + id}).responseText;
	$('#oIndex').val(oIndex);
}

var subForm = function(){
	var title = $.trim($('#title').val());
	if(title.length==0){
		subMess(208,108,'文档标题错误','<span class="red">对不起，请输入文档标题！</span>',$("#title"));
		return false;
	}else if(title.length>60){
		subMess(288,108,'文档标签错误','<span class="red">对不起，文档标题长度不能大于60个字符！</span>',$('#title'));
		return false;
	}
	var keywords = $.trim($('#keywords').val());
	if(keywords.length>30){
		subMess(268,108,'关键词错误','<span class="red">对不起，关键词长度不能大于30个字符！</span>',$('#keywords'));
		return false;
	}
	var description = $.trim($('#description').val());
	if(description.length>254){
		subMess(268,108,'描述错误','<span class="red">对不起，描述长度不能大于254个字符！</span>',$('#description'));
		return false;
	}
	
	//return false;
	$('#editForm').submit();
}
</script>